package com.example.fw;

import org.openqa.selenium.By;
import com.example.tests.ContactData;

public class ContactHelper extends HelperBase {

	public ContactHelper(AppManager manager) {
		super(manager);

	}

	public void initContactCreation() {
		click(By.linkText("add new"));
	}

	public void submitContactForm() {
		click(By.name("submit"));
	}

	public void fillContactForm(ContactData contact) {
		type(By.name("firstname"), contact.firstname);
		type(By.name("lastname"), contact.lastname);
		type(By.name("address"), contact.webaddress);
		type(By.name("home"), contact.homePhone);
		type(By.name("mobile"), contact.mobilePhone);
		type(By.name("work"), contact.workPhone);
		type(By.name("email"), contact.email);
		type(By.name("email2"), contact.email2);

		if (contact.dayOfBirth != null) {
			selectByText(By.name("bday"), contact.dayOfBirth);
		}
		if (contact.monthOfBirth != null) {
			selectByText(By.name("bmonth"), contact.monthOfBirth);
		}
		type(By.name("byear"), contact.yearOfBirth);
		// selectByText(By.name("new_group"), contact.newGroup);
		type(By.name("address2"), contact.address);
		type(By.name("phone2"), contact.phone2);
	}

	public void returnToMainPage() {
		click(By.linkText("home page"));
	}

	public void initContactModification() {
		click(By.xpath("//table[@id='maintable']/tbody/tr[2]/td[7]/a/img"));

	}

	public void submitContactModification() {
		click(By.xpath("(//input[@name='update'])[1]"));
		
	}

	public void deleteContact() {
		click(By.xpath("(//input[@name='update'])[2]"));
		
	}
	
	

}
